package com.cyh.core.login.service.user.impl;

import com.cyh.core.login.entity.UserInfo;
import com.cyh.core.login.repository.UserInfoRepository;
import com.cyh.core.login.service.user.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    UserInfoRepository userInfoRepository;

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public UserInfo getUserInfoByUid(Integer uid) {
        return userInfoRepository.findByUid(uid);
    }

    @Override
    public void updateUserInfo(UserInfo userInfo) {
        userInfoRepository.save(userInfo);
    }

    @Override
    public Map<String, Object> getAllUserInfoById(Integer id) {
        Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM `user_all_info` where uid="+id.intValue());
        return map;
    }

    @Override
    public List<Map<String, Object>> getAllUserInfo() {
        List<Map<String,Object>> lists = jdbcTemplate.queryForList("SELECT * FROM `user_all_info`");
        return lists;
    }

}
